# 1.导包
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.ie.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait

# 2.创建浏览器驱动对象
# Firefox浏览器:
# driver = webdriver.Firefox()
# Chrome浏览器:
path = r"D:\Programs\Python\Python313\chromedriver.exe"
ser = Service(executable_path = path)
driver = webdriver.Chrome(service = ser)
# 使用Edge浏览器,不需要安装驱动
# driver = webdriver.Edge ()
time.sleep(3)
# 3.打开Web页面
driver.get("http://121.43.169.97:8081/")
# 4.操作
driver.maximize_window()
driver.find_element(by=By.CSS_SELECTOR, value=".login").click()
time.sleep(3)
WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID, value="keywords"))
driver.find_element(by=By.ID, value="keywords").send_keys("14000000011")
driver.find_element(by=By.ID, value="password").send_keys("123456abc")
driver.find_element(by=By.ID, value="login-btn").click()
WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[2]/div[1]/a/em"))
information = driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[2]/div[1]/a/em").text
if information == "借款账户":
    driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[2]/div[1]/a").click()
WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]/a"))
driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]/a").click()
WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[1]/span/label[2]/input"))
driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[1]/span/label[2]/input").click()
WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.ID, value="amount_account"))
driver.find_element(by=By.ID, value="amount_account").send_keys("150000")
# WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[3]/textarea"))
driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[3]/textarea").send_keys("买房,买车")
# WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.ID, value="verifycode"))
driver.find_element(by=By.ID, value="verifycode").send_keys("8888")
# WebDriverWait(driver,10).until(lambda x: x.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[5]/input"))
driver.find_element(by=By.XPATH, value="/html/body/div[1]/div[2]/div[3]/div/div/div[3]/form/div[5]/input").click()

# 5.暂停
time.sleep(5)
# 6.关闭浏览器驱动对象
driver.quit()
